home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Samples / Media / Blend.vsh < prev    next >
Encoding:
Text File  |  2002-11-12  |  2.5 KB  |  93 lines

  1. vs.1.1
  2. ;------------------------------------------------------------------------------
  3. ; Constants specified by the app
  4. ;    c0      = (0,0,0,0)
  5. ;    c1      = (1,1,1,1)
  6. ;    c2      = (0,1,2,3)
  7. ;    c3      = (4,5,6,7)
  8. ;    c4-c7   = matWorld0
  9. ;    c8-c11  = matWorld1
  10. ;    c12-c15 = matViewProj
  11. ;    c20     = light direction
  12. ;    c21     = material diffuse color * light diffuse color
  13. ;    c22     = material ambient color
  14. ;
  15. ; Vertex components (as specified in the vertex DECL)
  16. ;    v0    = Position
  17. ;    v1.x  = Blend weight
  18. ;    v3    = Normal
  19. ;    v7    = Texcoords
  20. ;------------------------------------------------------------------------------
  21.  
  22. dcl_position v0
  23. dcl_blendweight v1
  24. dcl_normal v3
  25. dcl_texcoord v7
  26.  
  27.  
  28. ;------------------------------------------------------------------------------
  29. ; Vertex blending
  30. ;------------------------------------------------------------------------------
  31.  
  32. ; Transform position for world0 matrix
  33. dp4 r0.x, v0, c4
  34. dp4 r0.y, v0, c5
  35. dp4 r0.z, v0, c6
  36. dp4 r0.w, v0, c7
  37.  
  38. ; Transform position for world1 matrix
  39. dp4 r1.x, v0, c8
  40. dp4 r1.y, v0, c9
  41. dp4 r1.z, v0, c10
  42. dp4 r1.w, v0, c11
  43.  
  44. ; Lerp the two positions r0 and r1 into r2
  45. mul r0, r0, v1.x     ; v0 * weight
  46. add r2, c1.x, -v1.x  ; r2 = 1 - weight
  47. mad r2, r1, r2, r0   ; pos = (1-weight)*v1 + v0*weight
  48.  
  49. ; Transform to projection space
  50. dp4 oPos.x, r2, c12 
  51. dp4 oPos.y, r2, c13
  52. dp4 oPos.z, r2, c14
  53. dp4 oPos.w, r2, c15
  54.  
  55.  
  56. ;------------------------------------------------------------------------------
  57. ; Lighting calculation
  58. ;------------------------------------------------------------------------------
  59.  
  60. ; Transform normal for world0 matrix
  61. dp4 r0.x, v3, c4
  62. dp4 r0.y, v3, c5
  63. dp4 r0.z, v3, c6
  64. dp4 r0.w, v3, c7
  65.  
  66. ; Transform normal for world1 matrix
  67. dp4 r1.x, v3, c8
  68. dp4 r1.y, v3, c9
  69. dp4 r1.z, v3, c10
  70. dp4 r1.w, v3, c11
  71.  
  72. ; Lerp the two normals r0 and r1 into r2
  73. mul r0, r0, v1.x     ; v0 * weight
  74. add r2, c1.x, -v1.x  ; r2 = 1 - weight
  75. mad r2, r1, r2, r0   ; normal = (1-weight)*v1 + v0*weight
  76.  
  77. ; Do the lighting calculation
  78. dp3 r1.x, r2, c20    ; r1 = normal dot light
  79. max r1, r1.x, c0     ; if dot < 0 then dot = 0
  80. mul r0, r1.x, c21    ; Multiply with diffuse
  81. add r0, r0, c22      ; Add in ambient
  82. min oD0, r0, c1.x    ; clamp if > 1
  83.  
  84.  
  85. ;------------------------------------------------------------------------------
  86. ; Texture coordinates
  87. ;------------------------------------------------------------------------------
  88.  
  89. ; Just copy the texture coordinates
  90. mov oT0,  v7
  91.  
  92.  
  93.